﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.Gateway.Interfaces;
using Phoenix.ZeroMQConnectors;

namespace PServiceBus.Gateway.ZeroMQ {
    public class ZeroMQGatewayClient : IGatewayClient {
        private ZeroMQSender _client;

        public ZeroMQGatewayClient() { }

        public ZeroMQGatewayClient(string address) {
            _client = new ZeroMQSender(ZeroMQEndpointUri.Parse(address));
        }

        #region IGatewayClient Members

        public void Send<TCommand>(TCommand command) where TCommand : class {
            _client.Send<TCommand>(command);
        }

        public TResponse Send<TRequest, TResponse>(TRequest request)
            where TRequest : class
            where TResponse : class {
            return _client.Send<TRequest, TResponse>(request);
        }

        public IGatewayClient Init(string address) {
            return new ZeroMQGatewayClient(address);
        }

        #endregion

        #region IDisposable Members

        public void Dispose() {
            if (_client != null) _client.Dispose();
            _client = null;
        }

        #endregion
    }
}
